import request from '@/utils/request'


// 新增登记
export function add(data) {
  
  return request({
    url: '/project/add',
    method: 'post',
    data: data
  })
}
// 修改登记
export function update(data) {
  
  return request({
    url: '/contract/update',
    method: 'post',
    data: data
  })
}


// 查询
export function list(query){
 
  return request({
    url: '/project/list',
    method: 'get',
    params: query
  })
}

// 查询
export function selectDetail(query){
  
  return request({
    url: '/project/queryListByType',
    method: 'get',
    params: query
  })
}



// 修改定时任务调度
export function updateContract(data) {
  return request({
    url: '/contract/job',
    method: 'put',
    data: data
  })
}

function changeDate(dateString) {  
  // 将字符串转换为 Date 对象  
  let date = new Date(dateString);  

  // 检测日期是否有效  
  if (isNaN(date.getTime())) {  
      throw new Error("无效的日期字符串");  
  }  

  // 格式化为 yyyy-mm-dd  
  let formattedDate = date.toISOString().split('T')[0];  

  return formattedDate;  
} 

// 删除定时任务调度
export function delProject(id) {
  console.log("调用了删除")
  return request({
    url: '/project/' + id,
    method: 'delete'
  })
}

// 任务状态修改
export function changeJobStatus(jobId, status) {
  const data = {
    jobId,
    status
  }
  return request({
    url: '/monitor/job/changeStatus',
    method: 'put',
    data: data
  })
}


// 定时任务立即执行一次
export function runJob(jobId, jobGroup) {
  const data = {
    jobId,
    jobGroup
  }
  return request({
    url: '/monitor/job/run',
    method: 'put',
    data: data
  })}
